Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.1K
Visualizações
Getting this typescript error: Unsafe member access [key] on an any value

I have written a deep equality check function. I am getting this error for highlighted lines.

Can anyone suggest what I need to do to fix this error (or at least what the error means).

Code:

export const deepEqual = (object1: any, object2: any) => {
  const keys1 = Object.keys(object1);
  const keys2 = Object.keys(object2);
  if (keys1.length !== keys2.length) {
    return false;
  }
  for (const key of keys1) {
    const val1: unknown = object1[key] as unknown; // Error for this line
    const val2: unknown = object2[key] as unknown; // Error for this line
    const areObjects = isObject(val1) && isObject(val2);
    if (
      (areObjects && !deepEqual(val1, val2)) ||
      (!areObjects && val1 !== val2)
    ) {
      return false;
    }
  }
  return true;
};

Error:

45:27  error    Unsafe member access [key] on an any value     @typescript-eslint/no-unsafe-member-access
45:27  error    Unsafe member access [key] on an any value     @typescript-eslint/no-unsafe-member-access
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The errors mean, that you try to access a property (or member) of an object with type any. any in TS gives you no clues or knowledge about the values behind the variables.

ESLint displays an error, since accessing members of objects with type any can lead to unwanted (and maybe undetected) bugs. Your code will still compile, since TypeScript on its own has no problems with that. If you really know what you are doing, you can disable ESLint for certain lines by commenting

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access

above them.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda